<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var string = function(str){
    var len = str.length;
    bytelen = 0;
    if(str){
            for(i=0;i<len;i++){
                if(str.charCodeAt(i)>255){
                    bytelen = bytelen + 2;
                }
                else{
                    bytelen = bytelen + 1;
                }
            }
            return bytelen;
       }
       else{
            return 0;
      }
  }
  alert(string("你好，世界"));
  alert(string("Hello,world"));
</script>
</html>